package com.ruoyi.app.controller

import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.app.common.PageData
import com.ruoyi.app.domain.dto.MessageSearchDto
import com.ruoyi.app.domain.vo.InteractionMessageVo
import com.ruoyi.app.domain.vo.MemberMessageVo
import com.ruoyi.app.domain.vo.MessageIndexVo
import com.ruoyi.app.domain.vo.SystemMessageVo
import com.ruoyi.app.service.MessageApiService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("api/message")
@Api(tags = ["消息类相关接口"])
class MessageApiController {

    @Autowired
    private lateinit var messageApiService: MessageApiService

    /**
     * 用户消息列表
     */
    @ApiOperation("用户消息列表")
    @GetMapping("userMessageIndex")
    fun userMessageIndex(messageSearchDto: MessageSearchDto): Data<MessageIndexVo> = messageApiService.userMessageIndex(messageSearchDto)


    @ApiOperation("获取未读消息数量")
    @GetMapping("getUnReadMessageCount")
    fun getUnReadMessageCount(userId: Long): Data<Int> = Ok("获取成功", messageApiService.getUnReadMessageCount(userId))

    @ApiOperation("已读系统消息")
    @PostMapping("readSystemMessage")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "消息id 传递则为单个操作, 不传递或者传null则为全部操作",
            type = "path",
            required = false
        )
    )
    fun readSystemMessage(id: Long?): Data<Boolean> = messageApiService.readSystemMessage(id)

    @ApiOperation("已读会员消息")
    @PostMapping("readMemberMessage")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "消息id 传递则为单个操作, 不传递或者传null则为全部操作",
            type = "path",
            required = true
        )
    )
    fun readMemberMessage(id: Long?): Data<Boolean> = messageApiService.readMemberMessage(id)

    @ApiOperation("已读互动消息")
    @PostMapping("readInteractionMessage")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "消息id 传递则为单个操作, 不传递或者传null则为全部操作",
            type = "path",
            required = true
        )
    )
    fun readInteractionMessage(id: Long?): Data<Boolean> = messageApiService.readInteractionMessage(id)

    @ApiOperation("移除系统消息")
    @PostMapping("removeSystemMessage")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "消息id 传递则为单个操作, 不传递或者传null则为全部操作",
            type = "path",
            required = true
        )
    )
    fun removeSystemMessage(id: Long?): Data<Boolean> = messageApiService.removeSystemMessage(id)

    @ApiOperation("移除会员消息")
    @PostMapping("removeMemberMessage")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "消息id 传递则为单个操作, 不传递或者传null则为全部操作",
            type = "path",
            required = true
        )
    )
    fun removeMemberMessage(id: Long?): Data<Boolean> = messageApiService.removeMemberMessage(id)

    @ApiOperation("移除互动消息")
    @PostMapping("removeInteractionMessage")
    @ApiImplicitParams(
        ApiImplicitParam(
            name = "id",
            value = "消息id 传递则为单个操作, 不传递或者传null则为全部操作",
            type = "path",
            required = true
        )
    )
    fun removeInteractionMessage(id: Long?): Data<Boolean> = messageApiService.removeInteractionMessage(id)


    @ApiOperation("获取消息详情")
    @GetMapping("getMessageDetail")
    fun getMessageDetail(id: Long): Data<SystemMessageVo> = messageApiService.getMessageDetail(id)
}